package com.kool.kadmin.system.constant;

import lombok.Getter;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author luyu
 */
@Getter
public enum UserStateEnum {
    ACTIVE(1, "正常"),
    CLOSE(2, "关闭"),
    LOCK(3, "锁定");

    Integer code;
    String desc;

    UserStateEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static Map<Integer, UserStateEnum> codeToEnum = Stream.of(UserStateEnum.values()).collect(Collectors.toMap(UserStateEnum::getCode, self -> self));

    public static UserStateEnum getEnumByCode(Integer code) {
        return codeToEnum.get(code);
    }

    public static String getDescByCode(Integer code) {
        return codeToEnum.get(code) == null ? null : codeToEnum.get(code).getDesc();
    }
}
